package com.ruoyi.web.controller.campus;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.campus.domain.MyReply;
import com.ruoyi.campus.service.IMyReplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 留言板回复信息Controller
 *
 * @author zht
 * @date 2021-10-24
 */
@RestController
@RequestMapping("/campus/reply")
public class MyReplyController extends BaseController
{
    @Autowired
    private IMyReplyService myReplyService;

    /**
     * 查询留言板回复信息列表
     */
    @PreAuthorize("@ss.hasPermi('campus:reply:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyReply myReply)
    {
        startPage();
        List<MyReply> list = myReplyService.selectMyReplyList(myReply);
        return getDataTable(list);
    }

    /**
     * 导出留言板回复信息列表
     */
    @PreAuthorize("@ss.hasPermi('campus:reply:export')")
    @Log(title = "留言板回复信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyReply myReply)
    {
        List<MyReply> list = myReplyService.selectMyReplyList(myReply);
        ExcelUtil<MyReply> util = new ExcelUtil<MyReply>(MyReply.class);
        return util.exportExcel(list, "留言板回复信息数据");
    }

    /**
     * 获取留言板回复信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('campus:reply:query')")
    @GetMapping(value = "/{rId}")
    public AjaxResult getInfo(@PathVariable("rId") String rId)
    {
        return AjaxResult.success(myReplyService.selectMyReplyByRId(rId));
    }

    /**
     * 新增留言板回复信息
     */
    @PreAuthorize("@ss.hasPermi('campus:reply:add')")
    @Log(title = "留言板回复信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyReply myReply)
    {
        myReply.setrId(UUID.randomUUID().toString().replace("-",""));
        return toAjax(myReplyService.insertMyReply(myReply));
    }

    /**
     * 新增留言板回复(小程序端接口)
     */
    @PreAuthorize("@ss.hasAnyRoles('Administrator,member')")
    @Log(title = "留言板评论", businessType = BusinessType.INSERT)
    @PostMapping("/addForWx")
    public AjaxResult addForWx(@RequestBody MyReply myReply)
    {
        myReply.setReStatus("3");
        myReply.setrId(UUID.randomUUID().toString().replace("-",""));
        return toAjax(myReplyService.insertMyReply(myReply));
    }

    /**
     * 根据cId和cuserId修改留言板回复信息的状态(小程序端接口)
     */
    @PreAuthorize("@ss.hasAnyRoles('Administrator,member')")
    @GetMapping ("/updateReplyStatus")
    public AjaxResult updateReplyStatus(@RequestParam("cId") String cId,@RequestParam("cuserId") String cuserId)
    {
        return toAjax(myReplyService.updateReplyStatus(cId,cuserId));
    }

    /**
     * 根据cId获取评论信息
     */
    @PreAuthorize("@ss.hasAnyRoles('Administrator,member')")
    @GetMapping("/getReplyByCId")
    public List<Map<String,Object>> getReplyByCId(@RequestParam("cId") String cId){
        return myReplyService.getReplyByCId(cId);
    }

    /**
     * 修改留言板回复信息
     */
    @PreAuthorize("@ss.hasPermi('campus:reply:edit')")
    @Log(title = "留言板回复信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyReply myReply)
    {
        return toAjax(myReplyService.updateMyReply(myReply));
    }

    /**
     * 删除留言板回复信息
     */
    @PreAuthorize("@ss.hasPermi('campus:reply:remove')")
    @Log(title = "留言板回复信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rIds}")
    public AjaxResult remove(@PathVariable String[] rIds)
    {
        return toAjax(myReplyService.deleteMyReplyByRIds(rIds));
    }
}
